#pragma once
#include<functional>

class Timer
{
public:
	Timer() = default;
	~Timer() = default;

	void ret_start()
	{
		current_time = 0;
		shotted = false;
	}

	void set_finished(int time)
	{
		finished_time = time;
	}

	void set_one_shot(bool one)
	{
		one_shot = one;
	}

	void pause()
	{
		paused = true;
	}
	void resume()
	{
		paused = false;
	}

	void set_func(std::function<void()> fun)
	{
		func = fun;
	}

	void on_update(int interval)
	{
		if (paused)
			return;

		current_time += interval;

		if (current_time >= finished_time)
		{
			if ((!one_shot || (one_shot && !shotted)) && func)
			{
				func();
			}
			shotted = true;
			current_time = 0;
		}
	}

private:
	int current_time;
	int finished_time;
	bool paused = false;
	bool shotted = false;
	bool one_shot = false;
	std::function<void()> func;
};
